package com.wanlong.sys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanlong.sys.dao.SysRoleMapper;
import com.wanlong.sys.model.SysRole;
import com.wanlong.sys.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 万龙
 * @name
 * @project_name wanlong
 * @package_name com.wanlong.sys.service.impl
 * @description
 * @date 2019/2/23
 */
@Service
public class SysRoleService implements ISysRoleService {

    @Autowired
    private SysRoleMapper sysRoleMapper;

    public long insert(SysRole sysRole) {
        sysRoleMapper.insertSelective(sysRole);
        return sysRole.getId();
    }

    public int update(SysRole sysRole) {
        return sysRoleMapper.update(sysRole);
    }

    public int delete(SysRole sysRole) {
        return sysRoleMapper.delete(sysRole);
    }

    public PageInfo<SysRole> getPageSysRoleListByName(String name, Integer pageNo, Integer pageSize) {
        pageNo = pageNo == null?1:pageNo;
        pageSize = pageSize == null?10:pageSize;
        PageHelper.startPage(pageNo, pageSize);
        List<SysRole> list = sysRoleMapper.getSysRoleList(name);
        //用PageInfo对结果进行包装
        PageInfo<SysRole> page = new PageInfo<SysRole>(list);

        return page;
    }

    public List<SysRole> getAllSysRoleList() {
        List<SysRole> list = sysRoleMapper.getSysRoleList("");
        return list;
    }


}
